package com.ht.impl.demo;

import com.ht.impl.drawtool.DrawTool;
import com.ht.impl.drawtool.DrawToolBar;
import com.mxgraph.io.mxCodec;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxGraph;
import org.w3c.dom.Document;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2010-6-17
 */
public class DrawToolDemo extends JFrame {

    public DrawToolDemo() {
        super("Draw Tool Demo!");

        mxGraph graph = new mxGraph();
        final mxGraphComponent graphComponent = new mxGraphComponent(graph);
        Document styleDoc = mxUtils.loadDocument(this.getClass().getResource("/config/ht-style.xml").toString());
        mxCodec codec = new mxCodec();
        codec.decode(styleDoc.getDocumentElement(), graph.getStylesheet());

        getContentPane().setLayout(new BorderLayout());
        DrawToolBar bar = DrawToolBar.createBasicToolBar();
        bar.setContainer(graphComponent);
        mxCell cell = new mxCell("cloud", new mxGeometry(0, 0, 0, 0), "image;image=/com/mxgraph/examples/swing/images/cloud.png");
        cell.setVertex(true);
        bar.addDrawTool(new DrawTool(cell),
                this.getClass().getResource("/com/mxgraph/examples/swing/images/cloud.png"), "cloud");
        getContentPane().add(bar, BorderLayout.NORTH);
        getContentPane().add(graphComponent, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        DrawToolDemo frame = new DrawToolDemo();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }

}
